package com.atguigu.dga.assessor.calc;

import com.atguigu.dga.assessor.Assessor;
import com.atguigu.dga.dolphinscheduler.bean.TDsTaskInstance;
import com.atguigu.dga.dolphinscheduler.service.TDsTaskInstanceService;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component("TASK_FAILED")
public class TaskFailedAssessor extends Assessor {

    @Autowired
    TDsTaskInstanceService tDsTaskInstanceService;
    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {
        //获取表名
        String testName = assessParam.getTableMetaInfo().getSchemaName()+"."+assessParam.getTableMetaInfo().getTableName();
        //考评时间
        String assessDate = assessParam.getAssessDate();
        //查询当天的表的运行任务是否有报错
        List<TDsTaskInstance> tDsTaskInstances = tDsTaskInstanceService.selectFailedTask(assessDate, testName);

        if(tDsTaskInstances.size()>0){
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("该任务当日有报错");
        }

    }
}
